package com.controller;

import com.anno.BackLogin;
import com.anno.FrontLogin;
import com.controller.base.BaseController;
import com.controller.base.Response;
import com.model.JobInfo;
import com.service.JobInfoService;
import com.utils.from.BackJobInfoListForm;
import com.utils.from.FrontJobInfoListForm;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.swing.*;
import java.util.List;

@RestController
@RequestMapping("/jobInfo")
@Api("爬虫信息Controller")
public class JobInfoController extends BaseController {

    @Autowired
    private JobInfoService jobInfoService;

    @BackLogin
    @PostMapping("/list")
    public Response list(BackJobInfoListForm form) {
        Page<JobInfo> page = jobInfoService.list(form);
        return success(page);
    }


    @PostMapping("/getAllSimpleInfo")
    @ApiOperation(value = "获取所有记录信息", notes = "全表查询")
    public Response<List<JobInfo> > getAllSimpleInfo() {
        return success(jobInfoService.getAllSimpleInfo());
    }

    @PostMapping("/searchSimpleInfo")
    @ApiOperation(value = "根据条件查询记录信息", notes = "startDate:开始时间, endDate:结束时间, title:招聘标题")
    public Response<List<JobInfo>> searchSimpleInfo(String startDate, String endDate, String title) {
        List<JobInfo> result = jobInfoService.searchSimpleInfo(startDate, endDate, title);
        return success(result);
    }

    @PostMapping("/setHaveRead")
    @ApiOperation(value = "根据JobInfo.id设置已读标记")
    public Response setHaveRead(Long id) {
        //jobInfoService.setHaveRead(id);
        return success();
    }

    @GetMapping(value = "/test")
    @ApiOperation("根据JobInfo.id设置已读标记, 并重定向到captureUrl")
    public String viewCaptureUrl(Long id, String captureUrl) {
        jobInfoService.setHaveRead(id);
        return "redirect:" + captureUrl;
    }
}
